/*     */ package com.zimbra.qa.unittest;
/*     */ 
/*     */ import com.zimbra.client.ZGetMessageParams;
/*     */ import com.zimbra.client.ZMailbox;
/*     */ import com.zimbra.client.ZMessage;
/*     */ import com.zimbra.client.ZMessage.ZMimePart;
/*     */ import com.zimbra.cs.mime.handler.TextEnrichedHandler;
/*     */ import junit.framework.TestCase;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestGetMsg
/*     */   extends TestCase
/*     */ {
/*     */   private static final String USER_NAME = "user1";
/*  33 */   private static final String NAME_PREFIX = TestGetMsg.class.getSimpleName();
/*     */   private String mOriginalContentMaxSize;
/*     */   
/*     */   public void setUp()
/*     */     throws Exception
/*     */   {
/*  39 */     cleanUp();
/*  40 */     this.mOriginalContentMaxSize = TestUtil.getServerAttr("zimbraMailContentMaxSize");
/*     */   }
/*     */   
/*     */   public void testPlainMessageContent() throws Exception
/*     */   {
/*  45 */     doTestMessageContent("text/plain", "This is the body of a plain message.");
/*     */   }
/*     */   
/*     */   public void testHtmlMessageContent() throws Exception
/*     */   {
/*  50 */     doTestMessageContent("text/html", "<html><head></head><body>HTML message</body></html>");
/*     */   }
/*     */   
/*     */   public void testEnrichedMessageContent() throws Exception
/*     */   {
/*  55 */     doTestMessageContent("text/enriched", "<color><param>red</param>Blood</color> is <bold>thicker</bold> than<color><param>blue</param>water</color>.");
/*     */   }
/*     */   
/*     */   private void doTestMessageContent(String contentType, String body)
/*     */     throws Exception
/*     */   {
/*  61 */     ZMailbox mbox = TestUtil.getZMailbox("user1");
/*  62 */     MessageBuilder mb = new MessageBuilder();
/*     */     
/*  64 */     String subject = NAME_PREFIX + " testMessageContent " + contentType;
/*  65 */     String raw = mb.withSubject(subject).withBody(body).withContentType(contentType).create();
/*  66 */     String msgId = TestUtil.addRawMessage(mbox, raw);
/*  67 */     if (contentType.equals("text/enriched")) {
/*  68 */       body = TextEnrichedHandler.convertToHTML(body);
/*     */     }
/*     */     
/*  71 */     verifyMessageContent(mbox, msgId, false, null, null, false, body, contentType);
/*  72 */     verifyMessageContent(mbox, msgId, true, null, null, false, body, contentType);
/*  73 */     verifyMessageContent(mbox, msgId, false, Integer.valueOf(24), Integer.valueOf(24), true, body, contentType);
/*  74 */     verifyMessageContent(mbox, msgId, true, Integer.valueOf(24), Integer.valueOf(24), true, body, contentType);
/*     */     
/*     */ 
/*     */ 
/*  78 */     TestUtil.setServerAttr("zimbraMailContentMaxSize", "24");
/*  79 */     verifyMessageContent(mbox, msgId, false, null, Integer.valueOf(24), true, body, contentType);
/*  80 */     verifyMessageContent(mbox, msgId, true, null, Integer.valueOf(24), true, body, contentType);
/*     */   }
/*     */   
/*     */ 
/*     */   private void verifyMessageContent(ZMailbox mbox, String msgId, boolean wantHtml, Integer requestMaxLength, Integer expectedLength, boolean expectedTruncated, String body, String contentType)
/*     */     throws Exception
/*     */   {
/*  87 */     ZGetMessageParams params = new ZGetMessageParams();
/*  88 */     params.setId(msgId);
/*  89 */     params.setWantHtml(wantHtml);
/*  90 */     params.setMax(requestMaxLength);
/*  91 */     ZMessage msg = mbox.getMessage(params);
/*  92 */     ZMessage.ZMimePart mp = msg.getMimeStructure();
/*     */     
/*  94 */     assertEquals(expectedTruncated, mp.wasTruncated());
/*  95 */     String expected = body;
/*  96 */     if (expectedLength != null) {
/*  97 */       expected = body.substring(0, expectedLength.intValue());
/*     */     }
/*     */     
/* 100 */     if (contentType.equals("text/enriched"))
/*     */     {
/*     */ 
/*     */ 
/* 104 */       assertTrue(mp.getContent().length() > 0);
/* 105 */       assertTrue(expected.startsWith(mp.getContent()));
/*     */     } else {
/* 107 */       assertEquals(expected, mp.getContent());
/*     */     }
/*     */   }
/*     */   
/*     */   public void tearDown() throws Exception
/*     */   {
/* 113 */     cleanUp();
/* 114 */     TestUtil.setServerAttr("zimbraMailContentMaxSize", this.mOriginalContentMaxSize);
/*     */   }
/*     */   
/*     */   private void cleanUp() throws Exception
/*     */   {
/* 119 */     TestUtil.deleteTestData("user1", NAME_PREFIX);
/*     */   }
/*     */   
/*     */   public static void main(String[] args) throws Exception
/*     */   {
/* 124 */     TestUtil.cliSetup();
/* 125 */     TestUtil.runTest(TestGetMsg.class);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/TestGetMsg.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */